{% extends "base.html" %}
{% block title %}匹配打款列表{% end %}
{% block content %}
<div class="pace  pace-inactive">
    <div class="pace-progress" data-progress-text="100%" data-progress="99" style="width: 100%;">
        <div class="pace-progress-inner"></div>
    </div>
    <div class="pace-activity"></div>
</div>
<div id="wrapper">
    {% include 'admin_nav.html' %}
    <div id="page-wrapper" class="gray-bg dashbard-1">
        <div class="row border-bottom">
            {% include 'header_nav.html' %}
        </div>
        <div class="row wrapper border-bottom white-bg page-heading">
            <div class="col-lg-10">
                <h2>匹配打款列表</h2>
                <ol class="breadcrumb">
                    <li>
                        <a href="/admin/home">主页</a>
                    </li>


                </ol>
            </div>
            <div class="col-lg-2">

            </div>
        </div>
        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-lg-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-title">
                            <h5>

                            </h5>

                            <div class="ibox-tools">
                                <a class="collapse-link">
                                    <i class="fa fa-chevron-up"></i>
                                </a>

                                <a class="close-link">
                                    <i class="fa fa-times"></i>
                                </a>
                            </div>
                        </div>
                        <div class="ibox-content">
                            <style>
                                th:first-child,
                                .gradeX td:first-child {
                                    width: 20px;
                                    cursor: pointer;
                                }

                                th:first-child input,
                                .gradeX td:first-child input {
                                    cursor: pointer;
                                }
                            </style>
                               {%set provide_status={"waiting":"排单中","matching":"匹配中","matched":"已匹配","paid":"已打款","complete":"已完成"}%}
                            <form action="javascript:;" method="post" name="login_form" id="login_form">
                                {% module xsrf_form_html() %}
                                <table class="table table-striped table-bordered table-hover dataTables-example">
                                    <thead>
                                    <tr>
                                        <th><input type="checkbox" class="i-checks" id="userListCheck"/></th>
                                        <th>打款订单号码</th>
                                        <th>排期编号</th>
                                        <th>援助总金额</th>
                                        <th>打款用户编号</th>
                                        <th>受益人编号</th>
                                        <th>受益人银行</th>
                                        <th>受益人开户行地址</th>
                                        <th>受益人姓名</th>
                                        <th>受益人账户号码</th>
                                        <th>受益人微信号</th>
                                        <th>受益人支付宝</th>
                                        <th colspan="2">打款状态</th>
                                        <th>时间</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {%for p in match_record %}
                                    {%set pay=pay_info(p.get('mid'))%}
                                    {%if pay%}
                                    <tr class="gradeX">
                                        <td><input type="checkbox" class="i-checks"></td>
                                        <td class="userListId">{{p.get('order_id')}}</td>
                                        <td>{{p.get('help_id','未知')}}</td>
                                        <td>{{p.get('money')}}</td>
                                        <th>{{p.get('uid')}}</th>
                                        <th>{{p.get('mid')}}</th>
                                        <td>{{pay.get('bank',{}).get('name','')}}</td>
                                        <td>{{pay.get('bank',{}).get('address','')}}</td>
                                        <td>{{pay.get('bank',{}).get('user_name','')}}</td>
                                        <td>{{pay.get('bank',{}).get('card','')}}</td>
                                        <td>{{pay.get('wechat','')}}</td>
                                        <td>{{pay.get('alipay','')}}</td>
                                        <td> {%if p.get('paid') %}
                                            <span style="color:red">已打款</span>
                                            {%else%}
                                            未打款
                                            {%end%}
                                        </td>
                                        <td>
                                            {%if p.get('status') !='complete'%}
                                            <a href="javascript:;" data-oid="{{p.get('order_id')}}" data-hid="{{p.get('help_id')}}"
                                               class="confirm_paid">确认收款</a>
                                            {%else%}
                                            已确认
                                            {%end%}

                                        </td>
                                        <td>{{p['time']}}</td>
                                    </tr>
                                    {%end%}
                                    {% end %}
                                    </tbody>
                                </table>

                                <input type="button" class="btn btn-w-m btn-primary delete1" value="删除选中"
                                       data-toggle="modal" data-target="#myModal5" disabled/>

                                <!--<input type="button" class="btn btn-w-m btn-primary audit1" value="拉入黑名单"-->
                                <!--data-toggle="modal" data-target="#myModal6" disabled/>-->

                                <div class="modal inmodal fade" id="myModal5" tabindex="-1" role="dialog"
                                     aria-hidden="true">
                                    <div class="modal-dialog modal-lg">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal"><span
                                                        aria-hidden="true">&times;</span><span
                                                        class="sr-only">Close</span></button>
                                                <h4 class="modal-title">删除排队</h4>
                                                {#
                                                <small class="font-bold">删除排队</small>
                                                #}
                                            </div>
                                            <div class="modal-body">
                                                <p class="delete1Content"></p>
                                            </div>

                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-white deleteUserId"
                                                        data-dismiss="modal">确定
                                                </button>
                                                <button type="button" class="btn btn-primary" data-dismiss="modal">取消
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="modal inmodal fade" id="myModal6" tabindex="-1" role="dialog"
                                     aria-hidden="true">
                                    <div class="modal-dialog modal-lg">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal"><span
                                                        aria-hidden="true">&times;</span><span
                                                        class="sr-only">Close</span></button>
                                                <h4 class="modal-title">取消排队</h4>
                                                {#
                                                <small class="font-bold">取消排队</small>
                                                #}
                                            </div>
                                            <div class="modal-body">
                                                <p class="cancelContent"></p>
                                            </div>

                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-white cancelhelp"
                                                        data-dismiss="modal">确定
                                                </button>
                                                <button type="button" class="btn btn-primary" data-dismiss="modal">取消
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                            </form>
                            <script>


                                $(function () {

                                    var json1 = _alert('.btn.btn-w-m.delete1', '.modal-body .delete1Content', '您要删除的排期编号为');
                                    var json2 = _alert('.btn.btn-w-m.delete1', '.modal-body .cancelContent', '您要取消的排期编号为');

                                    var list_to_handle;

                                    $('tr.gradeX input[type="checkbox"],#userListCheck').click(function () {
                                        list_to_handle = listNubmer();
                                        console.log(listNubmer());
                                    });

                                    function getCookie(name) {
                                        var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
                                        return r ? r[1] : undefined;
                                    }

                                    $.ajaxSetup({
                                        beforeSend: function (xhr, settings) {
                                            if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type)) {
                                                xhr.setRequestHeader("X-XSRFToken", getCookie("_xsrf"));
                                            }
                                        }
                                    });

                                    $('.btn.btn-white.deleteUserId').click(function () {
                                        $.ajax({
                                            url: '/admin/delete_pay_match',
                                            type: 'delete',
                                            data: list_to_handle,
                                            success: function (data) {
                                                console.log(data);
                                            },
                                            error: function () {
                                                alert('error');
                                            }
                                        });
                                    });

                                    $('.btn.btn-white.cancelhelp').click(function () {
                                        $.ajax({
                                            url: '/admin/cancel_provide_help',
                                            type: 'put',
                                            data: list_to_handle,
                                            success: function (data) {
                                                console.log(data);
                                            },
                                            error: function () {
                                                alert('error');
                                            }
                                        });
                                    });
                                });
                            </script>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(".confirm_paid").click(function () {
        var base_url = "/admin/match_confirm_paid?order_id=";
        var oid = $(this).data("oid");
        var hid = $(this).data("hid");
        var tip = "警告!您确认已收到该匹配订单" + oid + "的款项吗?";
        if (confirm(tip)) {
            window.location = base_url + oid+"&"+"help_id="+hid;
            return true;
        }
        return false;
    });

</script>
{% end %}